#!/usr/bin/python
# -*- coding: UTF-8 -*-

import client_util
from datetime import datetime
from datetime import timedelta
import config
import json
import requests
import mysql_client

datetime_parttern = "%Y%m%d%H%M00"
tableName = 'surf_chn_mul_yer'
startTimeStr = '20200101000000'
endTimeStr = '20240101000000'
dataCode = 'SURF_CHN_MUL_YER'
interfaceId = 'getSurfEleInRegionByTime'

'''
    中国地面年值数据
'''
def getSurfEleInRegionByTime():

    #从数据库中查询
    lastData = mysql_client.select_data("SELECT times, try_times FROM {} WHERE times = (SELECT MAX(times) FROM {}) LIMIT 1".format(tableName, tableName))
    print(lastData)
    maxTimes = 0
    tryTimes = 0
    delta = 1

    if len(lastData) == 0:
        maxTimes = config.start_times
        tryTimes = 0
    else:
        maxTimes = lastData[0][u'times']
        tryTimes = lastData[0][u'try_times']

    if tryTimes > 4:
        delta = 2

    print('before maxTimes: {}, tryTimes: {}'.format(maxTimes, tryTimes))
    lastMaxDatetime = datetime.strptime(str(maxTimes), datetime_parttern)

    startDatetime = lastMaxDatetime + timedelta(days=365)
    formatted_time = startDatetime.strftime(datetime_parttern)

    print('after maxTimes: {}, tryTimes: {}'.format(maxTimes, tryTimes))
    doGetSurfEleInRegionByTime(formatted_time, tryTimes)

def initSurfEleInRegionByTime(db):

    '''
    初始化
    :return:
    '''

    startTime = datetime.strptime(startTimeStr, datetime_parttern)
    endTime = datetime.strptime(endTimeStr, datetime_parttern)

    times = ['20190101000000', '20200101000000', '20210101000000', '20220101000000', '20230101000000']

    for formatted_time in times:
        doGetSurfEleInRegionByTime(formatted_time, 1, db)

    # while startTime < endTime:
    #     startTime = startTime + timedelta(minutes=1)
    #     print(startTime)
    #     formatted_time = startTime.strftime(datetime_parttern)
    #     doGetSurfEleInRegionByTime(formatted_time, 1)


def doGetSurfEleInRegionByTime(times, tryTimes, db):
    '''
        中国地面分钟数据
    '''

    dic = {}
    dic['interfaceId'] = interfaceId
    dic['dataCode'] = dataCode
    dic['elements'] = 'Cnty,Station_Name,City,Town,Station_Id_C,Lat,Lon,Alti,Datetime,Year,Station_Id_d,PRS_Sensor_Alti,PRS_Avg,PRS_Max,PRS_Max_Days,PRS_Max_Odate,PRS_Min,PRS_Min_Days,PRS_Min_Odate,PRS_Sea_Avg,TEM_Avg,TEM_Year_Dev,TEM_Max_Avg,TEM_Min_Avg,TEM_Max,TEM_Max_Days,V12011_067,TEM_Min,TEM_Min_Days,V12012_067,TEM_Avg_Dev,TEM_Max_Dev,V12304_040,V12304_067,TEM_Min_Dev_Mon,TEM_Dev_Min_Days,TEM_Dev_Min_Odate,VAP_Avg,RHU_Avg,RHU_Min,RHU_Min_Days,V13007_067,PRE_Time_2020,PRE_Time_0808,SPRE_Time_2020,SPRE_Time_0808,PRE_Max_Day,PRE_Max_Mon_Days,V13052_067,Days_Max_Coti_PRE,PRE_Conti_Max,PRE_LCDays_EMon,EDay_Max_Coti_PRE,NPRE_LCDays,NPRE_LCDays_EMon,NPRE_LCDays_EDay,PRE_Max_Conti,Days_Max_Conti_PRE,PRE_Coti_Max_EMon,PRE_Coti_Max_EDay,PRE_Max_1h,PRE_Max_1h_Days,PRE_Max_1h_Odate,PRE_Max_1h_OMon,PRE_Max_1h_ODay,PRE_Days,Hail_Days,Mist_Days,V04330_001,ICE_Days,FlSa_Days,FlDu_Days,GaWIN_Days,SaSt_Days,Fog_Days,Thund_Days,Frost_Days,Snow_Days,GSS_Days,EVP_Big,Snow_Depth_Max,V13334_040,V13334_067,Snow_PRS,Snow_PRS_Max_Days,V13330_067,EICE_Wei_Max,EICEW_Max_Diam,EICEW_Max_Thick,V20440_040,EICED_Max_Odate,EICEW_Max_OMon,EICEW_Max_ODay,WIN_S_2mi_Avg,WIN_S_Max,WIN_D_S_Max_C,Days_WIN_S_Max,V11042_067,WIN_S_Inst_Max,WIN_D_INST_Max_C,V11046_040,WIN_S_INST_Max_ODate_C,WIN_NNE_Freq,WIN_NE_Freq,WIN_ENE_Freq,WIN_E_Freq,WIN_ESE_Freq,WIN_SE_Freq,WIN_SSE_Freq,WIN_S_Freq,WIN_SSW_Freq,WIN_SW_Freq,WIN_WSW_Freq,WIN_W_Freq,WIN_WNW_Freq,WIN_NW_Freq,WIN_NNW_Freq,WIN_N_Freq,WIN_C_Freq,WIN_D_Max_C,WIN_D_Max_Freq,WIN_D_SMax_C,WIN_D_SMax_Freq,WIN_S_Avg_NNE,WIN_S_Avg_NE,WIN_S_Avg_ENE,WIN_S_Avg_E,WIN_S_Avg_ESE,WIN_S_Avg_SE,WIN_S_Avg_SSE,WIN_S_Avg_S,WIN_S_Avg_SSW,WIN_S_Avg_SW,WIN_S_Avg_WSW,WIN_S_Avg__W,WIN_S_Avg_WNW,WIN_S_Avg_NW,WIN_S_Avg_NNW,WIN_S_Avg__N,WIN_S_Max_NNE,WIN_S_Max_NE,WIN_S_Max_ENE,WIN_S_Max_E,WIN_S_Max_ESE,WIN_S_Max_SE,WIN_S_Max_SSE,WIN_S_Max_S,WIN_S_Max_SSW,WIN_S_Max_SW,WIN_S_Max_WSW,WIN_S_Max_W,WIN_S_Max_WNW,WIN_S_Max_NW,WIN_S_Max_NNW,WIN_S_Max_N,GST_Avg,EGST_Max_Avg_Mon,GST_Min_Avg,GST_Min_Bel_0_Days,GST_Max,EGST_Max_Days,V12311_067,GST_Min,Days_GST_Min,V12121_067,GST_Avg_5cm,GST_Avg_10cm,GST_Avg_15cm,GST_Avg_20cm,GST_Avg_40cm,GST_Avg_80cm,GST_Avg_160cm,GST_Avg_320cm,LGST_Avg,LGST_Max_Avg,LGST_Min_Avg,LGST_Max,LGST_Max_Days,LGST_Max_Odate,LGST_Min,LGST_Min_Days,LGST_Min_Odate,FRS_Depth_Max,FRS_Depth_Max_Days,FRS_Depth_Max_Odate,SSH,SSP_Mon'
    dic['dataFormat'] = 'json'
    dic['times'] = times
    dic['adminCodes'] = config.adminCodes

    httpurl = client_util.getTqUrl(dic)
    print(httpurl)
    response = requests.get(url=httpurl)

    print('statusCode: {}'.format(response.status_code))
    if response.status_code != 200:
        insert_error(times, tryTimes, response.status_code, -1, db)
        return

    if response.content.isspace():
        insert_error(times, tryTimes, response.status_code, -2, db)
        return

    result = json.loads(response.content)
    returnCode = result['returnCode']
    print('resultCode: {}'.format(returnCode))

    if returnCode != '0':
        print('returnCode not available, code: {}'.format(returnCode))
        insert_error(times, tryTimes, response.status_code, returnCode, db)
        return

    if result['rowCount'] == '0':
        print('rowCount is 0')
        insert_error(times, tryTimes, response.status_code, returnCode, db)
        return

    DS = result['DS']

    for i in range(len(DS)):
        data = DS[i]

        tableData = {
            'times': times,
            'try_times': tryTimes,
            'status_code': response.status_code,
            'returnCode': returnCode,
            'Cnty': data[u'Cnty'].encode('utf8'),
            'Station_Name': data[u'Station_Name'].encode('utf8'),
            'City': data[u'City'].encode('utf8'),
            'Town': data[u'Town'].encode('utf8'),
            'Station_Id_C': data[u'Station_Id_C'].encode('utf8'),
            'Lat': data[u'Lat'].encode('utf8'),
            'Lon': data[u'Lon'].encode('utf8'),
            'Alti': data[u'Alti'].encode('utf8'),
            'Datetime': data[u'Datetime'].encode('utf8'),
            'Year': data[u'Year'].encode('utf8'),
            'Station_Id_d': data[u'Station_Id_d'].encode('utf8'),
            'PRS_Sensor_Alti': data[u'PRS_Sensor_Alti'].encode('utf8'),
            'PRS_Avg': data[u'PRS_Avg'].encode('utf8'),
            'PRS_Max': data[u'PRS_Max'].encode('utf8'),
            'PRS_Max_Days': data[u'PRS_Max_Days'].encode('utf8'),
            'PRS_Max_Odate': data[u'PRS_Max_Odate'].encode('utf8'),
            'PRS_Min': data[u'PRS_Min'].encode('utf8'),
            'PRS_Min_Days': data[u'PRS_Min_Days'].encode('utf8'),
            'PRS_Min_Odate': data[u'PRS_Min_Odate'].encode('utf8'),
            'PRS_Sea_Avg': data[u'PRS_Sea_Avg'].encode('utf8'),
            'TEM_Avg': data[u'TEM_Avg'].encode('utf8'),
            'TEM_Year_Dev': data[u'TEM_Year_Dev'].encode('utf8'),
            'TEM_Max_Avg': data[u'TEM_Max_Avg'].encode('utf8'),
            'TEM_Min_Avg': data[u'TEM_Min_Avg'].encode('utf8'),
            'TEM_Max': data[u'TEM_Max'].encode('utf8'),
            'TEM_Max_Days': data[u'TEM_Max_Days'].encode('utf8'),
            'V12011_067': data[u'V12011_067'].encode('utf8'),
            'TEM_Min': data[u'TEM_Min'].encode('utf8'),
            'TEM_Min_Days': data[u'TEM_Min_Days'].encode('utf8'),
            'V12012_067': data[u'V12012_067'].encode('utf8'),
            'TEM_Avg_Dev': data[u'TEM_Avg_Dev'].encode('utf8'),
            'TEM_Max_Dev': data[u'TEM_Max_Dev'].encode('utf8'),
            'V12304_040': data[u'V12304_040'].encode('utf8'),
            'V12304_067': data[u'V12304_067'].encode('utf8'),
            'TEM_Min_Dev_Mon': data[u'TEM_Min_Dev_Mon'].encode('utf8'),
            'TEM_Dev_Min_Days': data[u'TEM_Dev_Min_Days'].encode('utf8'),
            'TEM_Dev_Min_Odate': data[u'TEM_Dev_Min_Odate'].encode('utf8'),
            'VAP_Avg': data[u'VAP_Avg'].encode('utf8'),
            'RHU_Avg': data[u'RHU_Avg'].encode('utf8'),
            'RHU_Min': data[u'RHU_Min'].encode('utf8'),
            'RHU_Min_Days': data[u'RHU_Min_Days'].encode('utf8'),
            'V13007_067': data[u'V13007_067'].encode('utf8'),
            'PRE_Time_2020': data[u'PRE_Time_2020'].encode('utf8'),
            'PRE_Time_0808': data[u'PRE_Time_0808'].encode('utf8'),
            'SPRE_Time_2020': data[u'SPRE_Time_2020'].encode('utf8'),
            'SPRE_Time_0808': data[u'SPRE_Time_0808'].encode('utf8'),
            'PRE_Max_Day': data[u'PRE_Max_Day'].encode('utf8'),
            'PRE_Max_Mon_Days': data[u'PRE_Max_Mon_Days'].encode('utf8'),
            'V13052_067': data[u'V13052_067'].encode('utf8'),
            'Days_Max_Coti_PRE': data[u'Days_Max_Coti_PRE'].encode('utf8'),
            'PRE_Conti_Max': data[u'PRE_Conti_Max'].encode('utf8'),
            'PRE_LCDays_EMon': data[u'PRE_LCDays_EMon'].encode('utf8'),
            'EDay_Max_Coti_PRE': data[u'EDay_Max_Coti_PRE'].encode('utf8'),
            'NPRE_LCDays': data[u'NPRE_LCDays'].encode('utf8'),
            'NPRE_LCDays_EMon': data[u'NPRE_LCDays_EMon'].encode('utf8'),
            'NPRE_LCDays_EDay': data[u'NPRE_LCDays_EDay'].encode('utf8'),
            'PRE_Max_Conti': data[u'PRE_Max_Conti'].encode('utf8'),
            'Days_Max_Conti_PRE': data[u'Days_Max_Conti_PRE'].encode('utf8'),
            'PRE_Coti_Max_EMon': data[u'PRE_Coti_Max_EMon'].encode('utf8'),
            'PRE_Coti_Max_EDay': data[u'PRE_Coti_Max_EDay'].encode('utf8'),
            'PRE_Max_1h': data[u'PRE_Max_1h'].encode('utf8'),
            'PRE_Max_1h_Days': data[u'PRE_Max_1h_Days'].encode('utf8'),
            'PRE_Max_1h_Odate': data[u'PRE_Max_1h_Odate'].encode('utf8'),
            'PRE_Max_1h_OMon': data[u'PRE_Max_1h_OMon'].encode('utf8'),
            'PRE_Max_1h_ODay': data[u'PRE_Max_1h_ODay'].encode('utf8'),
            'PRE_Days': data[u'PRE_Days'].encode('utf8'),
            'Hail_Days': data[u'Hail_Days'].encode('utf8'),
            'Mist_Days': data[u'Mist_Days'].encode('utf8'),
            'V04330_001': data[u'V04330_001'].encode('utf8'),
            'ICE_Days': data[u'ICE_Days'].encode('utf8'),
            'FlSa_Days': data[u'FlSa_Days'].encode('utf8'),
            'FlDu_Days': data[u'FlDu_Days'].encode('utf8'),
            'GaWIN_Days': data[u'GaWIN_Days'].encode('utf8'),
            'SaSt_Days': data[u'SaSt_Days'].encode('utf8'),
            'Fog_Days': data[u'Fog_Days'].encode('utf8'),
            'Thund_Days': data[u'Thund_Days'].encode('utf8'),
            'Frost_Days': data[u'Frost_Days'].encode('utf8'),
            'Snow_Days': data[u'Snow_Days'].encode('utf8'),
            'GSS_Days': data[u'GSS_Days'].encode('utf8'),
            'EVP_Big': data[u'EVP_Big'].encode('utf8'),
            'Snow_Depth_Max': data[u'Snow_Depth_Max'].encode('utf8'),
            'V13334_040': data[u'V13334_040'].encode('utf8'),
            'V13334_067': data[u'V13334_067'].encode('utf8'),
            'Snow_PRS': data[u'Snow_PRS'].encode('utf8'),
            'Snow_PRS_Max_Days': data[u'Snow_PRS_Max_Days'].encode('utf8'),
            'V13330_067': data[u'V13330_067'].encode('utf8'),
            'EICE_Wei_Max': data[u'EICE_Wei_Max'].encode('utf8'),
            'EICEW_Max_Diam': data[u'EICEW_Max_Diam'].encode('utf8'),
            'EICEW_Max_Thick': data[u'EICEW_Max_Thick'].encode('utf8'),
            'V20440_040': data[u'V20440_040'].encode('utf8'),
            'EICED_Max_Odate': data[u'EICED_Max_Odate'].encode('utf8'),
            'EICEW_Max_OMon': data[u'EICEW_Max_OMon'].encode('utf8'),
            'EICEW_Max_ODay': data[u'EICEW_Max_ODay'].encode('utf8'),
            'WIN_S_2mi_Avg': data[u'WIN_S_2mi_Avg'].encode('utf8'),
            'WIN_S_Max': data[u'WIN_S_Max'].encode('utf8'),
            'WIN_D_S_Max_C': data[u'WIN_D_S_Max_C'].encode('utf8'),
            'Days_WIN_S_Max': data[u'Days_WIN_S_Max'].encode('utf8'),
            'V11042_067': data[u'V11042_067'].encode('utf8'),
            'WIN_S_Inst_Max': data[u'WIN_S_Inst_Max'].encode('utf8'),
            'WIN_D_INST_Max_C': data[u'WIN_D_INST_Max_C'].encode('utf8'),
            'V11046_040': data[u'V11046_040'].encode('utf8'),

            'WIN_S_INST_Max_ODate_C': data[u'WIN_S_INST_Max_ODate_C'].encode('utf8'),
            'WIN_NNE_Freq': data[u'WIN_NNE_Freq'].encode('utf8'),
            'WIN_NE_Freq': data[u'WIN_NE_Freq'].encode('utf8'),
            'WIN_ENE_Freq': data[u'WIN_ENE_Freq'].encode('utf8'),
            'WIN_E_Freq': data[u'WIN_E_Freq'].encode('utf8'),
            'WIN_ESE_Freq': data[u'WIN_ESE_Freq'].encode('utf8'),
            'WIN_SE_Freq': data[u'WIN_SE_Freq'].encode('utf8'),
            'WIN_SSE_Freq': data[u'WIN_SSE_Freq'].encode('utf8'),
            'WIN_S_Freq': data[u'WIN_S_Freq'].encode('utf8'),
            'WIN_SSW_Freq': data[u'WIN_SSW_Freq'].encode('utf8'),
            'WIN_SW_Freq': data[u'WIN_SW_Freq'].encode('utf8'),
            'WIN_WSW_Freq': data[u'WIN_WSW_Freq'].encode('utf8'),
            'WIN_W_Freq': data[u'WIN_W_Freq'].encode('utf8'),
            'WIN_WNW_Freq': data[u'WIN_WNW_Freq'].encode('utf8'),
            'WIN_NW_Freq': data[u'WIN_NW_Freq'].encode('utf8'),
            'WIN_NNW_Freq': data[u'WIN_NNW_Freq'].encode('utf8'),
            'WIN_N_Freq': data[u'WIN_N_Freq'].encode('utf8'),
            'WIN_C_Freq': data[u'WIN_C_Freq'].encode('utf8'),
            'WIN_D_Max_C': data[u'WIN_D_Max_C'].encode('utf8'),
            'WIN_D_Max_Freq': data[u'WIN_D_Max_Freq'].encode('utf8'),
            'WIN_D_SMax_C': data[u'WIN_D_SMax_C'].encode('utf8'),
            'WIN_D_SMax_Freq': data[u'WIN_D_SMax_Freq'].encode('utf8'),
            'WIN_S_Avg_NNE': data[u'WIN_S_Avg_NNE'].encode('utf8'),
            'WIN_S_Avg_NE': data[u'WIN_S_Avg_NE'].encode('utf8'),
            'WIN_S_Avg_ENE': data[u'WIN_S_Avg_ENE'].encode('utf8'),
            'WIN_S_Avg_E': data[u'WIN_S_Avg_E'].encode('utf8'),
            'WIN_S_Avg_ESE': data[u'WIN_S_Avg_ESE'].encode('utf8'),
            'WIN_S_Avg_SE': data[u'WIN_S_Avg_SE'].encode('utf8'),
            'WIN_S_Avg_SSE': data[u'WIN_S_Avg_SSE'].encode('utf8'),
            'WIN_S_Avg_S': data[u'WIN_S_Avg_S'].encode('utf8'),
            'WIN_S_Avg_SSW': data[u'WIN_S_Avg_SSW'].encode('utf8'),
            'WIN_S_Avg_SW': data[u'WIN_S_Avg_SW'].encode('utf8'),
            'WIN_S_Avg_WSW': data[u'WIN_S_Avg_WSW'].encode('utf8'),
            'WIN_S_Avg__W': data[u'WIN_S_Avg__W'].encode('utf8'),
            'WIN_S_Avg_WNW': data[u'WIN_S_Avg_WNW'].encode('utf8'),
            'WIN_S_Avg_NW': data[u'WIN_S_Avg_NW'].encode('utf8'),
            'WIN_S_Avg_NNW': data[u'WIN_S_Avg_NNW'].encode('utf8'),
            'WIN_S_Avg__N': data[u'WIN_S_Avg__N'].encode('utf8'),
            'WIN_S_Max_NNE': data[u'WIN_S_Max_NNE'].encode('utf8'),
            'WIN_S_Max_NE': data[u'WIN_S_Max_NE'].encode('utf8'),
            'WIN_S_Max_ENE': data[u'WIN_S_Max_ENE'].encode('utf8'),
            'WIN_S_Max_E': data[u'WIN_S_Max_E'].encode('utf8'),
            'WIN_S_Max_ESE': data[u'WIN_S_Max_ESE'].encode('utf8'),
            'WIN_S_Max_SE': data[u'WIN_S_Max_SE'].encode('utf8'),
            'WIN_S_Max_SSE': data[u'WIN_S_Max_SSE'].encode('utf8'),
            'WIN_S_Max_S': data[u'WIN_S_Max_S'].encode('utf8'),
            'WIN_S_Max_SSW': data[u'WIN_S_Max_SSW'].encode('utf8'),
            'WIN_S_Max_SW': data[u'WIN_S_Max_SW'].encode('utf8'),
            'WIN_S_Max_WSW': data[u'WIN_S_Max_WSW'].encode('utf8'),
            'WIN_S_Max_W': data[u'WIN_S_Max_W'].encode('utf8'),
            'WIN_S_Max_WNW': data[u'WIN_S_Max_WNW'].encode('utf8'),
            'WIN_S_Max_NW': data[u'WIN_S_Max_NW'].encode('utf8'),
            'WIN_S_Max_NNW': data[u'WIN_S_Max_NNW'].encode('utf8'),
            'WIN_S_Max_N': data[u'WIN_S_Max_N'].encode('utf8'),
            'GST_Avg': data[u'GST_Avg'].encode('utf8'),
            'EGST_Max_Avg_Mon': data[u'EGST_Max_Avg_Mon'].encode('utf8'),
            'GST_Min_Avg': data[u'GST_Min_Avg'].encode('utf8'),
            'GST_Min_Bel_0_Days': data[u'GST_Min_Bel_0_Days'].encode('utf8'),
            'GST_Max': data[u'GST_Max'].encode('utf8'),
            'EGST_Max_Days': data[u'EGST_Max_Days'].encode('utf8'),
            'V12311_067': data[u'V12311_067'].encode('utf8'),
            'GST_Min': data[u'GST_Min'].encode('utf8'),
            'Days_GST_Min': data[u'Days_GST_Min'].encode('utf8'),
            'V12121_067': data[u'V12121_067'].encode('utf8'),
            'GST_Avg_5cm': data[u'GST_Avg_5cm'].encode('utf8'),
            'GST_Avg_10cm': data[u'GST_Avg_10cm'].encode('utf8'),
            'GST_Avg_15cm': data[u'GST_Avg_15cm'].encode('utf8'),
            'GST_Avg_20cm': data[u'GST_Avg_20cm'].encode('utf8'),
            'GST_Avg_40cm': data[u'GST_Avg_40cm'].encode('utf8'),
            'GST_Avg_80cm': data[u'GST_Avg_80cm'].encode('utf8'),
            'GST_Avg_160cm': data[u'GST_Avg_160cm'].encode('utf8'),
            'GST_Avg_320cm': data[u'GST_Avg_320cm'].encode('utf8'),
            'LGST_Avg': data[u'LGST_Avg'].encode('utf8'),
            'LGST_Max_Avg': data[u'LGST_Max_Avg'].encode('utf8'),
            'LGST_Min_Avg': data[u'LGST_Min_Avg'].encode('utf8'),
            'LGST_Max': data[u'LGST_Max'].encode('utf8'),
            'LGST_Max_Days': data[u'LGST_Max_Days'].encode('utf8'),
            'LGST_Max_Odate': data[u'LGST_Max_Odate'].encode('utf8'),
            'LGST_Min': data[u'LGST_Min'].encode('utf8'),
            'LGST_Min_Days': data[u'LGST_Min_Days'].encode('utf8'),
            'LGST_Min_Odate': data[u'LGST_Min_Odate'].encode('utf8'),
            'FRS_Depth_Max': data[u'FRS_Depth_Max'].encode('utf8'),
            'FRS_Depth_Max_Days': data[u'FRS_Depth_Max_Days'].encode('utf8'),
            'FRS_Depth_Max_Odate': data[u'FRS_Depth_Max_Odate'].encode('utf8'),
            'SSH': data[u'SSH'].encode('utf8'),
            'SSP_Mon': data[u'SSP_Mon'].encode('utf8')
        }

        mysql_client.insert_data(tableData, tableName, db)

def insert_error(times, tryTimes, status_code, returnCode, db):

    """

    :param times:
    :param tryTimes:
    :return:
    """

    tableData = {
        'times': times,
        'try_times': tryTimes + 1,
        'status_code': status_code,
        'returnCode': returnCode
    }

    mysql_client.insert_data(tableData, tableName, db)

if __name__ == "__main__":
    #getSurfEleInRegionByTime()
    db = mysql_client.connect_db()
    initSurfEleInRegionByTime(db)
    db.close()
